//
//  yuanhuaPlaneAppDelegate.m
//  yuanhuaPlane
//
//  Created by zhuyuanbin on 6/22/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "yuanhuaPlaneAppDelegate.h"
#import "mainViewController.h"
#import "SplashScreen.h"
#import "xmlReader.h"
@implementation yuanhuaPlaneAppDelegate

@synthesize window;

@synthesize splashView;
@synthesize tabBarCon;
@synthesize shopViewNav;
@synthesize searchViewNav;
mainViewController *mainController;

-(void)removeSplash:(id)sender
{
	if([splashView superview])
		[splashView removeFromSuperview];
}
-(void)readXml
{
	xmlReader *xmlrd = [[xmlReader alloc] init];
	[xmlrd analyMainXml];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch
	
	UIWindow *aWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
	self.window = aWindow;
	[aWindow release];
	 
	SplashScreen *scrn = [[SplashScreen alloc] init];
	splashView = [scrn splashWithImageNamed:nil andLabel:@"Loading"];
	splashView.autoresizesSubviews = YES;
	splashView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
	[window addSubview:splashView];
	[splashView release];
	[self readXml];
	[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(setFinalView) userInfo:nil repeats:NO];
	
	[window makeKeyAndVisible];
	
	return YES;
}
-(void)setFinalView
{
	NSMutableArray *viewControllerArray = [NSMutableArray array];
	
	mainController = [[mainViewController alloc] init];
	shopViewNav = [[UINavigationController alloc] initWithRootViewController:mainController];
	[mainController release];
	[viewControllerArray addObject:shopViewNav];
	tabBarCon = [[UITabBarController alloc]init];
	tabBarCon.delegate = self;
	tabBarCon.viewControllers = viewControllerArray;
	tabBarCon.view.autoresizesSubviews = YES;
	tabBarCon.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
	[self.window insertSubview:tabBarCon.view belowSubview:splashView];
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(removeSplash:)];
	[UIView setAnimationDuration:1];
	[splashView setAlpha:0.01];
	[UIView commitAnimations];

}

- (void)dealloc {
    [window release];
	[mainController release];
    [super dealloc];
}


@end
